import time
from os.path import *

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from utils.webdriver_factory import WebDriverFactory

driver = WebDriverFactory.get_instance()
file_path = "../template/select.html"
abs_path = abspath(file_path)
# 打开本地html文件
driver.get("file:///" + abs_path)

time.sleep(3)

select_element = driver.find_element(By.ID, 'select_value')
# build select
select = Select(select_element)
# 通过索引选择，从0开始
select.select_by_index(1)
time.sleep(2)
# 通过value属性的值选择
select.select_by_value('2')
time.sleep(3)
# 通过显示的文本选择
select.select_by_visible_text('val1')
time.sleep(3)
